<?php

require_once 'Ext/User/Action/Edit/Password/Abstract.php';

class Ext_User_Action_Edit_Password_Adapter_Ucenter extends Ext_User_Action_Edit_Password_Abstract
{
    public function editPassword($password)
    {

        $result = array(
            'code'  => Ext_User_Action_Edit_Password_Result::FAILURE,
            'messages' => array(),
            );
        $_appModelDbTableUserAccountBaseUsername = App_Model_DbTable_User_Account_Base_Username::getInstance();
        $_userAccountBaseUsernameRow = $_appModelDbTableUserAccountBaseUsername->getRowByUserId($this->_userId);
        if(!isset($_userAccountBaseUsernameRow['username']) || $_userAccountBaseUsernameRow['username'] == '')
        {
            $_result = $this->setResult(Ext_User_Action_Edit_Password_Result::MESSAGE_USERNAME_NOT_FOUND);
            return $_result;
        }
        $_username = $_userAccountBaseUsernameRow['username'];
        $_extAccountUcenter = new Ext_Account_Ucenter();
        $uid = $_extAccountUcenter->changePassword($_username, $password);

    	if($uid > 0) {
			$_result = $this->setResult(Ext_User_Action_Edit_Password_Result::SUCCESS);
            return $_result;
	    } elseif($uid == 0) {
			$_result = $this->setResult(Ext_User_Action_Edit_Password_Result::SUCCESS);
            return $_result;
		} elseif($uid == -7) {
			$_result = $this->setResult(Ext_User_Action_Edit_Password_Result::FAILURE);
            return $_result;
		} elseif($uid == -8) {
		    $_result = $this->setResult(Ext_User_Action_Edit_Password_Result::FAILURE_USER_IS_PROTECTED);
            return $_result;
		} else {
			$_result = $this->setResult(Ext_User_Action_Edit_Password_Result::FAILURE_UNCATEGORIZED);
            return $_result;
		}

    }
    
    
}
